package tests;

import static org.junit.Assert.*;

import java.io.File;

import model.DataManagerModel;
import manager.FileManager;
import org.junit.Test;

public class DataManagerModelTests {

	@Test
	public void testDataManagerModel() {
		DataManagerModel dm = new DataManagerModel();
		assertNotNull(dm.isDataStructureInitialized());
	}

	@Test
	public void testAddFileManager() {
		DataManagerModel dm = new DataManagerModel();
		assertTrue("Should be true", dm.isDataStructureInitialized() && dm.getDataSetSize() == 0);
		dm.addFileManager("testrecipe", "test", "1 oz beef", "directions", "none", "");
		assertTrue(dm.getDataSetSize() > 0);
		File rf = new File(FileManager.getDefaultRecipePath() + "testrecipe.rcp");
		if(rf.exists()){
			rf.delete();
		}
	}

	@Test
	public void testSetCurrentFileManager() {
		FileManager fm = new FileManager();
		DataManagerModel dm = new DataManagerModel();
		dm.setCurrentFileManager(fm);
		assertTrue(dm.getCurrentFileManager() == fm);
	}

	@Test
	public void testGetCurrentFileManager() {
		testSetCurrentFileManager();
	}

	@Test
	public void testModifyFileManager() {
		FileManager fm = new FileManager("test");
		DataManagerModel dm = new DataManagerModel();
		fm.createRecipe("test", "testing", "2 c sugar", "instructions", "", "tags");
		dm.setCurrentFileManager(fm);
		assertTrue(dm.getCurrentFileManager().getData().getRecipeName().equals("test"));
		
		dm.modifyFileManager("revised", "test", "1 tsp salt", "directions", "none", "");
		assertTrue(dm.getCurrentFileManager().getData().getRecipeName().equals("revised"));
		
		File f = new File(FileManager.getDefaultRecipePath() + "revised.rcp");
		if(f.exists()){
			f.delete();
		}
	}

}
